﻿//----------------------------------------------
// Flip Web Apps: Game Framework
// Copyright © 2016 Flip Web Apps / Mark Hewitt
//
// Please direct any bugs/comments/suggestions to http://www.flipwebapps.com
// 
// The copyright owner grants to the end user a non-exclusive, worldwide, and perpetual license to this Asset
// to integrate only as incorporated and embedded components of electronic games and interactive media and 
// distribute such electronic game and interactive media. End user may modify Assets. End user may otherwise 
// not reproduce, distribute, sublicense, rent, lease or lend the Assets. It is emphasized that the end 
// user shall not be entitled to distribute or transfer in any way (including, without, limitation by way of 
// sublicense) the Assets in any other way than as integrated components of electronic games and interactive media. 

// The above copyright notice and this permission notice must not be removed from any files.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//----------------------------------------------

using System.Diagnostics;
using UnityEditor;
using UnityEngine;

namespace GameFramework.GameFramework.Editor {
    /// <summary>
    /// Adds commands for opening in certain applications.
    /// See https://unity3d.com/learn/tutorials/modules/intermediate/editor/menu-items
    /// </summary>

    public class OpenWith : MonoBehaviour {

        [MenuItem("Assets/Open With.../Notepad++", false, -8002)]
        static void OpenWithNotepadPlusPlus()
        {
            var selected = Selection.activeObject;
            //TODO find pat\
            Process.Start(@"C:\Program Files (x86)\Notepad++\notepad++.exe", "\"" + AssetDatabase.GetAssetPath(selected) + "\"");
        }

        [MenuItem("Assets/Open With.../Excel", false, -8002)]
        static void OpenWithExcel()
        {
            var selected = Selection.activeObject;
            //TODO find path
            Process.Start(@"C:\Program Files\Microsoft Office\root\Office16\Excel.exe", "\"" + AssetDatabase.GetAssetPath(selected) + "\"");
        }

        /// <summary>
        /// 
        /// Note that we pass the same path, and also pass "true" to the second argument.
        /// </summary>
        /// <returns></returns>
        [MenuItem("Assets/Open With.../Notepad++", true, -8002)]
        static bool OpenWithNotepadPlusPlusValidation()
        { 
            // This returns true when the selected object is of the given type (the menu item will be disabled otherwise).
            return true; // Selection.activeObject.GetType() == typeof(MonoScript);
        }

        /// <summary>
        /// 
        /// Note that we pass the same path, and also pass "true" to the second argument.
        /// </summary>
        /// <returns></returns>
        [MenuItem("Assets/Open With.../Excel", true, -8002)]
        static bool OpenWithExcelValidation()
        {
            // This returns true when the selected object is of the given type (the menu item will be disabled otherwise).
            return true; // Selection.activeObject.GetType() == typeof(MonoScript);
        }
    }
}